package com.building.hcrm.common;

import java.util.List;

import com.building.hcrm.base.BaseParam;
import com.building.hcrm.model.SysMenu;
import com.building.hcrm.model.SysUser;
import com.building.hcrm.wcf.UserServiceProxy;

import android.content.Context;
import android.util.Log;

public class SysMenuList
{
	private final String  LTAG= SysMenuList.class.getSimpleName();
	
	private static SysMenuList _instance;
	private Context _context;
	
	public static SysMenuList getInstance(Context context)
	{
		if (_instance == null)
		{
			_instance = new SysMenuList();
		}
		_instance._context = context;
		return _instance;
	}
	
	private List<SysMenu> _list;

	public List<SysMenu> initList()
	{
		try
		{
			if (_list == null || _list.size() == 0)
			{
				BaseParam param = new BaseParam();
				param.userNum = User.getInstance(_context).getUserNum();
				_list = UserServiceProxy.getInstance(_context).MenuLoad(param);
			}
		}
		catch (Exception e)
		{
			Log.e(LTAG, ComFunc.getExceptionMessage(e),e);
		}
		return _list;
	}
	
	public String getMenuName(String strToken)
	{
		String strRe = null;
		if(null != _list)
		{
			for(SysMenu sm : _list)
			{
				if(sm.MenuToken.equals(strToken))
				{
					strRe = sm.MenuName;
					break;
				}
			}
		}
		return strRe;
	}
	
	public String getMenuName(String strToken,String strType)
	{
		String strRe = null;
		if(null != _list)
		{
			for(SysMenu sm : _list)
			{
				if(sm.MenuToken.equals(strToken) && sm.MenuType.equals(strType))
				{
					strRe = sm.MenuName;
					break;
				}
			}
		}
		return strRe;
	}
	
	public List<SysMenu> getList()
	{
		return _list;
	}
}
